package com.jxy.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class ConsumerService {
	@Autowired
	private RestTemplate restTemplate;

	@HystrixCommand(fallbackMethod = "addFallback")
	public String add() {
		return restTemplate
				.getForEntity("http://CONFIG-CLIENT/add?a=10&b=20",
						Integer.class).getBody().toString();
	}

	// add 方法调用失败时调用此方法
	public String addFallback() {
		return "调用时发生了异常";
	}
}
